#ifndef IPCONNECTION_H
#define IPCONNECTION_H



#include <QObject>
#include <QString>
#include <QStringList>
#include <QMutex>
#include <QMutexLocker>
#include "clientthread.h"


class IpConnection : public QObject
{
    Q_OBJECT
public:
    IpConnection(ClientThread * cth);
    ~IpConnection();

    void abort(bool wait_closed = false, bool lock = true);
    void forceAbort(bool wait_closed = false, bool lock = true);
    void pushBack(ClientThread *cth);
    int erase(ClientThread *cth);
    quint64 threadsTotalUpload(bool lock = true);
    quint64 threadsTotalDownload(bool lock = true);
    quint64 threadsUploadSpeed(bool lock = true);
    quint64 threadsDownloadSpeed(bool lock = true);
    QStringList threadsObjectList();


    inline int size() {
        return threads.size();
    }

    QVector <ClientThread *> threads;
    QString _ip;

private slots:
    void threadDisconnected(ClientThread *);

private:
    bool aborted;
    QMutex mutex;

    qint64 uploaded, downloaded;
};


#endif // IPCONNECTION_H
